package com.wz.jiangsu.testnetvine;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

/**
 * @program: wz
 * @author: wangzhou
 * @create: 2024-11-18 17:14
 * @description:
 **/
public class A {

    static Properties properties;
    static KafkaProducer<String, String> kafkaProducer;
    public static void main(String[] args) {
        properties = new Properties();
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"10.25.10.24:9093");
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class);
        properties.put(ProducerConfig.BATCH_SIZE_CONFIG, 16 * 1024* 2);
        properties.put(ProducerConfig.LINGER_MS_CONFIG,2);
        properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG,33554432);
        properties.put(ProducerConfig.COMPRESSION_TYPE_CONFIG,"snappy");
//        properties.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG,"transactional_id_01");
        properties.put("security.protocol", "SASL_PLAINTEXT");
        properties.put("sasl.mechanism", "PLAIN");
        properties.put("sasl.jaas.config", "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"wt\" password=\"Netvine123\";");
        kafkaProducer = new KafkaProducer(properties);



        for (int i = 0; i < 5; i++) {
            String str = "{\"alertCount\":1,\"alertSourceIp\":\"101.1.1.1\",\"alertSourceMac\":\"101:11:AA:BB:11:11\",\"alertSourcePort\":\"10111\",\"alertTargetIp\":\"101.1.2.1\",\"alertTargetMac\":\"\",\"alertTargetPort\":\"10211\",\"cveId\":\"\",\"dataSourceType\":\"\",\"equipment\":\"EVENT_FIREWALL\",\"eventCode\":\"\",\"eventDescription\":\"防火墙白名单防护策略阻断了来自101.1.1.1的流量,源端口:10111,目的IP:101.1.2.1,目的端口:10211,协议:TCP.\",\"eventId\":\"62\",\"eventTitle\":\"\",\"eventType\":\"AB-ABBLEVENT\",\"factory\":\"netvine\",\"msgTime\":1731919177,\"msgType\":\"EVENT_FIREWALL_WHITELISTSYSLOG\",\"operateResult\":\"阻断\",\"originLog\":\"Oct 24 10:00:00 netvine/1.100.100.11 {\\\"logType\\\": 4,\\\"time\\\":\\\"2024-11-18 16:39:37\\\",\\\"message\\\": {\\\"sourceIp\\\":\\\"101.1.1.1\\\",\\\"destinationIp\\\":\\\"101.1.2.1\\\",\\\"sourceMac\\\":\\\"101:11:AA:BB:11:11\\\",\\\"sourcePort\\\":\\\"10111\\\",\\\"destinationPort\\\":\\\"10211\\\",\\\"protocol\\\":\\\"TCP\\\",\\\"description\\\":\\\"ETH4\\\",\\\"whiteListId\\\":2,\\\"whiteListName\\\":\\\"防火墙-白名单日志\\\",\\\"action\\\":2}}\",\"protocol\":\"TCP\",\"riskLevel\":2,\"ruleGroup\":\"\",\"sourceIp\":\"1.100.100.11\",\"suggestion\":\"\",\"threatName\":\"Block:防火墙白名单防护策略阻断事件,白名单名:防火墙-白名单日志,协议:TCP\",\"time\":1731919178,\"userName\":\"netvine\",\"uuid\":\"ef9de34a-55b9-47ed-8109-bb75a5dedaa7\"}";
            kafkaProducer.send(new ProducerRecord<>("syslog_dev",str));
            System.out.println(i);
        }

        // 执行一些全局初始化操作
        System.out.println("init .........");
    }
}
